import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import Unocss from 'unocss/vite'
import Icons from 'unplugin-icons/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'



// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
  return {
    base: './',
    plugins: [vue(), Unocss(), AutoImport({
      imports: ['vue', 'vue-router'],
      dts: true,
    }), Icons({
      autoInstall: true,
      compiler: 'vue3',
      defaultClass: 'inline-block',
    })],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      }
    },
    /*     css: {
          preprocessorOptions: {
            scss: {
              //最好只引入sass变量，其他则在main.ts中全局import使用；当前如果不生效，则在app.vue中设置 <style lang="scss" scoped >
              additionalData: '@use "@/styles/common.scss" as *;',
            }
          },
        }, */
    server: {
      host: "0.0.0.0",
      proxy: {
        "/api": {
          target: 'http://192.168.100.29:8088',
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/api/, "")
        }
      },
      port: 3302

    },
    build: {
      rollupOptions: {
        output: {
          // 最小化拆分包
          manualChunks: (id) => {
            if (id.includes('node_modules')) {
              return id.toString().split('node_modules/')[1].split('/')[0].toString();
            }
          },
          // 用于从入口点创建的块的打包输出格式[name]表示文件名,[hash]表示该文件内容hash值
          entryFileNames: 'js/[name].[hash].js',
          // 用于命名代码拆分时创建的共享块的输出命名
          chunkFileNames: 'js/[name].[hash].js',
          // 用于输出静态资源的命名，[ext]表示文件扩展名
          assetFileNames: '[ext]/[name].[hash].[ext]',
        }
      }
    }
  }
})


